package edu.df.carcell4.service.impl;

import edu.df.carcell4.mapper.DfCustomMapper;
import edu.df.carcell4.model.DfCustom;
import edu.df.carcell4.service.DfCustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DfCustomServiceImpl implements DfCustomService {


    @Autowired
    private DfCustomMapper dfCustomMapper;


    @Override
    public DfCustom create(DfCustom dfCustomToCreate) {

        dfCustomToCreate.setCreateTime(new Date());
        this.dfCustomMapper.insert(dfCustomToCreate);
        return dfCustomToCreate;
    }

    @Override
    public List<DfCustom> findAll() {

        List<DfCustom> dfCustoms = this.dfCustomMapper.selectAll();
        return dfCustoms;
    }

    @Override
    public DfCustom find(Long id) {

        DfCustom dfCustom = this.dfCustomMapper.selectByPrimaryKey(id);
        return dfCustom;
    }

    @Override
    public boolean update(DfCustom dfCustomToUpdate) {
        int i = this.dfCustomMapper.updateById(dfCustomToUpdate);
        return i > 0;
    }

    @Override
    public boolean delete(Long id) {

        int i = this.dfCustomMapper.deleteByPrimaryKey(id);
        return i > 0;
    }
}
